package psd.views;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import psd.core.CodeEvaluator;


public class CodeProblemsCommand extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
				.getActiveMenuSelection(event);		
		Object firstElement = selection.getFirstElement();
		if (firstElement instanceof IJavaProject) {
		
			CodeEvaluator evaluator = new CodeEvaluator((IJavaProject)firstElement);			
			evaluator.FindProblems();			
			showMessage("PSD executed");
		
		}
		return null;

	}

	private void showMessage(String message) {
		MessageDialog.openInformation(null, "PSD", message);
	}
	
	
}